<?php

namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;

class RechargeLogController  extends Controller
{

    public function list($yearMonth,$openid){
        $query = DB::table('tbl_product_recharge_log');
        if ($yearMonth) {
            $query = $query->whereBetween('dt_order_time',[$yearMonth.'-01 00:0:0',$yearMonth.'-31 23:59:59']);
        }
        if ($openid) {
            $query = $query->where('openid',$openid);
        }
        $total = $query->count();
        $list = $query->orderBy('dt_order_time','desc')->get();
        return response([
            'success' => true,
            'total'   => $total,
            'items'   => $list
        ]);
    }

    public function detail($id){
        $query = DB::table('tbl_product_recharge_log');
        if ($id) {
            $query = $query->where('i_id',$id);
        }
        $data = $query->get()->first();
        return $data;
    }
}
